function [SampleTimeRange, RevEndTime] = stmgen(varargin)
% Generating Sampling Time Vector based on the frequency
% Usage:
%   [SampleTimeRange, RevEndTime] = stmgen(Freq, EndTime, SigData)
% Output:
%   SampleTimeRange : Sampling time sequence aligned with signal data
%   RevEndTime      : Revised time end
% Input:
%   Freq    : Sampling frequency of the signal (should be aligned with the signal
%   EndTime : End time of the signal
%   SigData : Time based signal (ECG data)
%
% Note:
%   - Generating the sampling time for signal data
%   - SigData == 0 : Sampling Time generated by End Time and Frequency
%   - EndTime == 0 : Sampling time generated by Signal Data
%	
% Made by Amang Kim [v0.9 || 1/31/2019]
% Package of amgecg (Amang ECG) Toolbox [Rel Ver. 0.5 || 2/1/2019]


%-----------------------------
%(Freq, EndTime, SigData)
inputs={'Freq', 'EndTime', 'SigData'};
SigData = 0;

for n=1:nargin
    if(~isempty(varargin{n}))
        eval([inputs{n} '=varargin{n};'])
    end
end
%-----------------------------



f=Freq;

if SigData ~= 0 
    l0 = length (SigData);
else
    l0 = f*EndTime+1;
end

if EndTime == 0    
    l0= length(SigData);
else
    l0 = f*EndTime+1;
end




stm0=[0:1/f:(l0-1)/f];
stm_len=length(stm0);

if stm_len > l0
    stm0 = stm0(1:l0);
    stm_len = l0;
end

SampleTimeRange = stm0(:);
RevEndTime = stm0(stm_len);

end

